package com.bokee.archerwq.lab.mina.codec;

import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

import com.bokee.archerwq.lab.mina.message.Request;

public class RequestDecoder extends CumulativeProtocolDecoder {

	@Override
	protected boolean doDecode(IoSession session, ByteBuffer in,
			ProtocolDecoderOutput out) throws Exception {
		if (in.remaining() >= 10) {
			Request request = new Request();
			byte[] bytes = new byte[10];
			in.get(bytes);
			request.setId(new String(bytes));
			out.write(request);
			return true;
		} else {
			return false;
		}
	}

}
